﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nuzzle.Managers
{
    public static class TicketManager
    {
        public static Dictionary<string, Ticket> Tickets = new Dictionary<string, Ticket>();

        public static void AddTicket(Ticket t)
        {
            lock (Tickets)
            {
                if (!Tickets.ContainsKey(t.Key))
                {
                    Tickets.Add(t.Key, t);
                }
            }
        }

        public static Ticket GetAndDestroy(string key)
        {
            lock (Tickets)
            {
                if (Tickets.ContainsKey(key))
                {
                    var t = Tickets[key];
                    Tickets.Remove(key);
                    return t;
                }
                else
                {
                    return null;
                }
            }
        }

        public class Ticket
        {
            public string Key { get; set; }
            public Database.Models.AccountModel Account { get; set; }

            public Ticket(string key, Database.Models.AccountModel account)
            {
                this.Key = key;
                this.Account = account;
            }
        }
    }
}
